package com.hamal;

import org.junit.Test;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * @author Conceit
 * @since 1.0.0, 2017/11/8
 */
public class ADS60RainData {

    @Test
    public void test() throws ParseException {
        //当前设备数据
        Object obj = new String("//////////////////56/////////////////////////////////////////////////////////////////////////////////////////////////655");
        String AWSTime = new String("2017-11-07 06:10:00.000");
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.sss");

        Date time = sdf.parse(AWSTime);


        Double dou = null;
        String str = null;


        //处理aws降水数据

        //获取aws数据数值
        String awsRain60minData = (String) obj;
        //转换为charArray
        char[] awsRain60minDataArray = awsRain60minData.toCharArray();
        //获取aws数据产生时间
        Date deviceTimestamp = time;
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(deviceTimestamp);
        //根据时间的分钟，
        int awsMinute = calendar.get(Calendar.MINUTE);

        //获取对应降水数值的位数上对应的数据

        //处理0分的数据
        if (awsMinute == 0 || awsMinute == 60) {
            dou = Double.valueOf(awsRain60minData.substring(awsRain60minData.length() - 2));
        }
        //其他分钟的数据
        else {
            int after = awsMinute * 2;
            int before = after - 2;
            dou = Double.valueOf(awsRain60minData.substring((before), (after)));
        }
    }


}
